package cronjob

import (
	"context"
	"github.com/jinzhu/copier"
	"go-zero-admin/application/applet/api/internal/svc"
	"go-zero-admin/application/applet/api/internal/types"
	job "go-zero-admin/application/job/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateCronStatusByIdLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 修改定时任务状态
func NewUpdateCronStatusByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCronStatusByIdLogic {
	return &UpdateCronStatusByIdLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateCronStatusByIdLogic) UpdateCronStatusById(req *types.UpdateCronStatusByIdReq) (resp *types.UpdateCronStatusByIdRes, err error) {
	res, err := l.svcCtx.JobCronSvc.ModifyCron(l.ctx, &job.ModifyScheduleStatusReq{TaskId: uint32(req.TaskId)})
	if err != nil {
		return nil, err
	}
	resp = &types.UpdateCronStatusByIdRes{}
	_ = copier.Copy(resp, res)

	return resp, nil
}
